package org.bees.cms.web.util.velocity.editer;

import java.io.Serializable;

import net.sf.json.JSONObject;

import org.bees.cms.web.util.Beans;

public class TextEditer extends AbstractEditer {
	private Integer size = 30;

	@Override
	public void initialize(JSONObject json) throws Exception {
		super.initialize(json);
		size = json == null ? size : json.containsKey("size") ? json.getInt("size") : size;
	}

	@Override
	public String edit(Serializable t) throws Exception {
		value = t == null ? value : Beans.getString(t, property);
		StringBuilder builder = new StringBuilder();
		builder.append("<input");
		builder.append(" id='" + id + "'");
		builder.append(" class='" + clazz + "'");
		builder.append(" style='" + style + "'");
		builder.append(" type='text'");
		builder.append(" name='" + name + "'");
		builder.append(" value='" + value + "'");
		builder.append(" size='" + size + "'");
		builder.append(" placeholder='" + placeholder + "'");
		builder.append(" validator='" + validator + "'");
		builder.append(" />");
		return builder.toString();
	}

	@Override
	public void destroy() throws Exception {
		super.destroy();
		size = null;
	}

	public Integer getSize() {
		return size;
	}

	public void setSize(Integer size) {
		this.size = size;
	}

}
